package MethodReference.练习;

import java.util.ArrayList;

public class 练习二 {
    public static void main(String[] args) {
        /**
         * 需求:
         *      创建集合添加学生对象
         *      学生对象属性:name,age
         *要求:
         *      获取姓名放到数组当中
         *      使用方法引用完成
         */
        ArrayList<StudentTwo>list=new ArrayList<>();
        list.add(new StudentTwo("zhangsan",23));
        list.add(new StudentTwo("lisi",24));
        list.add(new StudentTwo("wangwu",25));

//        String[] strings = list.stream().map(new Function<StudentTwo, String>() {
//            @Override
//            public String apply(StudentTwo studentTwo) {
//                return studentTwo.getName();
//            }
//        }).toArray(String[]::new);
//
//        System.out.println(Arrays.toString(strings));

        String[] toArray = list.stream()
                .map(StudentTwo::getName)
                .toArray(String[]::new);

        for (String s : toArray) {
            System.out.println(s);
        }
    }
}
